﻿namespace EyeOpen.Market.Client.Service.Wcf
{
    using System;
    using EyeOpen.Market.Client.Service.Wcf.MarketServiceReference;

    public class MarketServiceAsynchronous : IMarketServiceAsynchronous
    {
        private readonly MarketServiceClient marketServiceClient;

        public MarketServiceAsynchronous()
        {
            marketServiceClient = new MarketServiceClient();
            marketServiceClient.GetCustomerListCompleted += MarketServiceClientGetCustomerListCompleted;
        }

        public event EventHandler<CustomerListEventArgs> CustomerListLoaded;

        public void GetAllCustomer()
        {
            marketServiceClient.GetCustomerListAsync();
        }

        private void MarketServiceClientGetCustomerListCompleted(object sender, GetCustomerListCompletedEventArgs e)
        {
            var handler = CustomerListLoaded;
            
            if (handler != null)
            {
                handler(this, new CustomerListEventArgs(e.Result));
            }
        }
    }
}